package org.springframework.beans.factory.test.noobTest;

import org.springframework.beans.factory.anno.Autowired;
import org.springframework.beans.factory.anno.Value;

/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2019/11/13
 */
public class ABean{
    public String name;
    public int age;
    public int money;
    public CBean cBean;
    public DBean dBean;

    @Autowired(required = false)
    public ABean(@Value("lry") String name, @Value("20")int age, int money, DBean dBean, CBean cBean){
        //构造器参数@Autowired(true/false)效果一样，都会被注入，spring也是如此
        this.name = name;
        this.age = age;
        this.money = money;
        this.cBean = cBean;
        this.dBean = dBean;
    }

    @Autowired(required = false)
    public ABean(@Value("100") int age){
        this.age = age;
    }

    @Autowired(required = false)
    public ABean(@Value("lry") String name){
        this.name = name;
    }

    public ABean(){
    }

    @Override
    public String toString() {
        return age+name+money+cBean+dBean;
    }

    public void doSth(){
        System.out.println("do");
    }

    public void init(){
        System.out.println("init");
    }

//    public static void main(String[] args) {
//        Constructor<?>[] cs = ABean.class.getDeclaredConstructors();
//        for (Constructor c:cs) {
//            Parameter[]params = c.getParameters();
//            for(Parameter par:params){
//                System.out.print(par.getName()+" ");
//            }
//            System.out.println();
//        }
//    }

//    public static void main(String[] args) throws ClassNotFoundException {
//
//        LocalVariableTableParameterNameDiscoverer localVariableTableParameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
//        Class<?> forName = Class.forName(ABean.class.getName());
//        Constructor<?>[] constructors = forName.getConstructors();
//        for (Constructor<?> constructor : constructors) {
//            String[] parameterNames = localVariableTableParameterNameDiscoverer.getParameterNames(constructor);
//            for (String parameterName : parameterNames) {
//                System.out.print(parameterName + " ");
//            }
//            System.out.println();
//        }
//
//    }


    //    public static void main(String[] args) {
//        ABean a = new ABean();
//        CBean c = new CBean();
//        a.cBean = c;
//        c = null;
//        System.out.println(a);
//    }

//    public static void main(String[] args) {
//        CBean cBean = new CBean();
//        ABean aBean = new ABean();
//        cBean.aBean = aBean;
//
//        aBean.age = 20;
//        aBean.name = "lry";
//        System.out.println(cBean);
//    }

}
